<template>
  <div class="con">
    <div class="contbox6_10">
      <p class="titlelist6_10">
        商学院
        <span style="color: #999">&nbsp;&nbsp;/&nbsp;&nbsp;</span>常见问题管理
      </p>
      <div class="content">
        <div class="sousuojg6_10">
          <el-form ref="form" :model="form" label-width="100px">
            <el-form-item label="问题分类" style="float: left;">
              <el-input v-model="form.typeName"></el-input>
            </el-form-item>
            <el-form-item label="创建人" style="float: left;">
              <el-input v-model="form.createName"></el-input>
            </el-form-item>
            <el-form-item label="修改人" style="float: left;">
              <el-input v-model="form.updateName"></el-input>
            </el-form-item>
            <el-form-item label="创建时间">
              <el-date-picker
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="开始日期"
                v-model="form.createStartDate"
                style="width: 100%"
              ></el-date-picker>
              <div class="times">-</div>
              <el-date-picker
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="结束日期"
                v-model="form.createEndDate"
                style="width: 100%"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="修改时间">
              <el-date-picker
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="开始日期"
                v-model="form.updateStartDate"
                style="width: 100%"
              ></el-date-picker>
              <div class="times">-</div>
              <el-date-picker
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="结束日期"
                v-model="form.updateEndDate"
                style="width: 100%"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </div>
        <div class="buttons">
          <el-button type="primary" @click="handleSelectLists">搜索</el-button>
          <el-button @click="resetTheSearch">重置</el-button>
           <el-button
            class="butt"
            style="float: left; margin-left: 40px"
            type="primary"
            icon="el-icon-plus"
            v-if="isAuth('mechanismAdd')"
            @click="onnew"
            >问题分类</el-button>
        </div>
        <el-table
          :data="list"
          tooltip-effect="dark"
          :header-cell-style="{ background: '#F9FAFC', color: '#222' }"
          stripe
          border
          :row-style="{ height: '0px' }"
          :cell-style="{ padding: '0px' }"
          ref="multipleTable"
        >
          <!-- <el-table-column width="60px" type="index" label="序号" ></el-table-column> -->
          
          <el-table-column min-width="200" label="问题分类" prop="typeName"></el-table-column>
          <el-table-column min-width="160" label="创建人" prop="createName"></el-table-column>
          <el-table-column min-width="160" label="修改人" prop="updateName"></el-table-column>
          <el-table-column min-width="160" label="创建时间" prop="createDate"></el-table-column>
          <el-table-column min-width="160" label="修改时间" prop="updateDate"></el-table-column>
          <el-table-column show-overflow-tooltip min-width="200" label="操作">
            <template slot-scope="scope">
              <el-button type="text" @click="cat(scope.row)">查看</el-button>
              <el-button type="text" @click="cat1(scope.row)">修改</el-button>
              <el-button type="text" @click="extension(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div style="font-size: 16px; margin-top: 30px">
          <el-pagination
            style="text-align: right"
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="form.page"
            :page-sizes="[20, 50, 100]"
            :page-size="form.number"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          ></el-pagination>
        </div>
      </div>
      <el-dialog
        :title="dialogFormTitle"
        :visible.sync="dialogFormWindows"
        width="500px"
        :close-on-click-modal="false">
        <el-form :model="forms" ref="forms" label-width="80px">
          <el-row>
              <el-form-item
                style="width:350px !important"
                class="officeName"
                label="问题分类"
                prop="typeName"
                :rules="{ required: true,  message: '请输入问题分类', trigger: 'blur' }"
              >
                <el-input
                  placeholder="请输入问题分类"
                  v-model="forms.typeName"
                  :disabled="dis"
                  >
                </el-input>
              </el-form-item>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormWindows = false">取 消</el-button>
          <el-button type="primary" @click="create('forms')">确 定</el-button>
        </div>
    </el-dialog>
     <el-dialog
        title="删除确认"
        :visible.sync="dialogFormWindows1"
        width="500px"
        :close-on-click-modal="false">
         <span v-if="flag==0">确认删除该内容？</span>
         <span v-if="flag==1">该分类下级有常见问题，是否确认删除该内容</span>

      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormWindows1 = false">取 消</el-button>
        <el-button type="primary" @click="sure">确 定</el-button>
      </div>
    </el-dialog>
    </div>
  </div>
</template>

<script>
import https from "../../plugins/https.js";
import { CompareDate } from "../../assets/js/commion";
export default {
  data() {
    return {
      dis:false,
      dialogFormWindows:false,
      dialogFormWindows1:false,
      val: "",
      dialogFormTitle:"",
      total: 0,
      flag:"0",
      form: {
        updateName:"",
        createName:"",//创建人
        createStartDate:"",//创建开始时间
        createEndDate:"",//创建结束时间
        updateStartDate:"",//修改开始时间
        updateEndDate:"",//修改结束时间
        typeName:"",
        page: 1,
        number: 20
      },
      forms:{
        uid:"",
        typeName:""
      },
      list: [],
      bussinessType: []
    };
  },
  created() {
    this.lists();
  },
  methods: {
    // 点击删除
    extension(val){
      this.dialogFormWindows1=true
      this.val=val.uid
      https.delProblem({uid:val.uid}).then(res=>{
        console.log("是否有")
        console.log(res)
        this.flag = res.data.flag
      }).catch(err=>{
        console.log(err)
      })
    },
    // 删除确定
    sure(){
      https.saveSchoolQuestionType({uid:this.val,delFlag:"1"}).then(res=>{
          if(res.data.code=="0000"){
            this.dialogFormWindows1=false
            this.lists()
          }else{
            layer.open({
              content:res.data.msg,
              skin: "msg",
              time: 1, //1秒后自动关闭
            });
          }
         })
    },
    // 查看
    cat(val){
      this.forms.uid=val.uid
      this.forms.typeName=val.typeName
      this.dialogFormTitle="查看问题分类"
      this.dialogFormWindows=true
      this.dis=true
    },
    // 修改
    cat1(val){
      this.forms.uid=val.uid
      this.forms.typeName=val.typeName
      this.dialogFormTitle="修改问题分类"
      this.dialogFormWindows=true
      this.dis=false
    },
    // 添加问题
    onnew(){
      this.dialogFormWindows=true
      this.forms.typeName=""
      this.dis=false
      this.forms.uid=""
      this.dialogFormTitle="添加问题分类"
       this.dis=false

    },
    create() {
      this.$refs["forms"].validate(valid => {
        if (valid) {
         https.saveSchoolQuestionType(this.forms).then(res=>{
          if(res.data.code=="0000"){
            this.dialogFormWindows=false
            this.lists()
          }else{
            layer.open({
              content:res.data.msg,
              skin: "msg",
              time: 1, //1秒后自动关闭
            });
          }
         })
        }
      });
    },
    //列表
    lists(){
      https.schoolQuestionTypeList(this.form).then(res=>{
        if(res.data.code=="0000"){
          this.list=res.data.data
          this.total=res.data.total
        }else{
          layer.open({
            content:res.data.msg,
            skin: "msg",
            time: 1, //1秒后自动关闭
          });
        }
      }).catch(err=>{})
    },
    //搜索
    handleSelectLists() {
       if (this.form.createStartDate != "" && this.form.createEndDate != "") {
        if (CompareDate(this.form.createStartDate, this.form.createEndDate)) {
          this.form.page = 1;
          this.lists();
        } else {
          layer.open({
            content: "结束时间不能早于开始时间",
            skin: "msg",
            time: 1, //1秒后自动关闭
          });
        }
      }else if(this.form.updateStartDate!=""&&this.form.updateEndDate!=""){
        if (CompareDate(this.form.updateStartDate, this.form.updateEndDate)) {
          this.form.page = 1;
          this.lists();
        } else {
          layer.open({
            content: "结束时间不能早于开始时间",
            skin: "msg",
            time: 1, //1秒后自动关闭
          });
        }
      } 
      else {
        this.form.page = 1;
        this.lists();
      }
    },
    // 校验时间的一个方法
    warrys() {
      layer.open({
        content: "结束时间不能早于开始时间",
        skin: "msg",
        time: 2 //1秒后自动关闭
      });
    },
    // 重置
    resetTheSearch() {
      this.form = {
        updateName:"",
        createName:"",//创建人
        createStartDate:"",//创建开始时间
        createEndDate:"",//创建结束时间
        updateStartDate:"",//修改开始时间
        updateEndDate:"",//修改结束时间
        typeName:"",
        page: 1,
        number: 20
      };
      this.lists();
    },
    //每页几条数据
    handleSizeChange(val) {
      this.SelectData = [];
      this.form.number = val; //动态改变
      this.form.page = 1;
      this.lists();
    },
    //当前页
    handleCurrentChange(val) {
      this.SelectData = [];
      this.form.page = val; //动态改变
      this.lists();
    }
  }
};
</script>

<style scoped>
.con {
  position: relative;
}
/* 单独样式 */
.contbox6_10 {
  width: 100%;
  overflow-x: auto;
  box-sizing: border-box;
  float: left;
}
.sousuojg6_10 {
  width: 100%;
}
.times {
  width: 20px;
  display: inline-block;
  text-align: center;
}
.buttons > .el-button {
  width: 100px;
  padding: 7px;
  height: 32px;
}
</style>